package com.lvkerry.orderfood.provider.store;

import com.lvkerry.orderfood.provider.WxDevelopIdStore;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.concurrent.TimeUnit;

/**
 * @author Kerry on 18/03/08
 */
public class RedisWxDevelopIdStore implements WxDevelopIdStore {

    private StringRedisTemplate redisTemplate;

    public RedisWxDevelopIdStore(RedisConnectionFactory connectionFactory) {
        this.redisTemplate = new StringRedisTemplate(connectionFactory);
    }

    @Override
    public void setCache(String token, long expire) {
        redisTemplate.opsForValue().set(WEI_XIN_DEVELOP_ID, token, expire, TimeUnit.SECONDS);
    }

    @Override
    public String getCache() {
        return redisTemplate.opsForValue().get(WEI_XIN_DEVELOP_ID);
    }

    @Override
    public long getExpiry() {
        return redisTemplate.getExpire(WEI_XIN_DEVELOP_ID);
    }
}
